package com.dayuanit.booksystem.v3.client;

import java.io.*;
import java.net.Socket;

/**
 * 大猿图书客户端系统
 */
public class BookSystemClient {
    public static void main(String[] args) throws Exception {
        Socket socket = new Socket("212.64.69.194", 9999);

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                    String result = null;
                    while (null != (result = bufferedReader.readLine())) {
                        System.out.println(">>>" + result);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, "处理服务端响应的线程").start();

        new Thread(new Runnable() {
            @Override
            public void run() {

                try {
                    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));

                    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                    String data = null;
                    while (null != (data = br.readLine())) {
                        bw.write(data);
                        bw.newLine();
                        bw.flush();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, "键盘输入线程").start();

    }
}
